package com.cty.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor1 implements HandlerInterceptor {

    /*
    * 调用handler之前处理
    * 放行或者不放行
    * 返回true放行false不放行
    * 参数：请求对象  响应对象 处理器方法对象
    * */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("MyInterceptor1.preHandle");
        return true;
    }

    /*调用handler之后的处理
    *
    * 处理一些敏感内容
    *
    *
    * 参数:请求对象 响应对象 handler方法对象 视图和共享域对象
    *
    *
    * */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("MyInterceptor1.postHandle");
    }

    /*
    * 返回数据给前端前
    *
    * 参数 请求对象 响应对象 handler对象 异常对象
    *
    *
    * */

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("MyInterceptor1.afterCompletion");
    }
}
